package algorithm.swordoff;

/**
 * 斐波那契数列
 */

public class SQ10_1 {

    public int fib(int n) {
        int[] ints = {0, 1};

        for (int i = 0; i < n; i++) {
            recursion(ints);
        }
        return ints[0];
    }

    // 原地修改数组,节省空间
    private void recursion(int[] temp) {
        int sum = (temp[1]+temp[0])%1000000007;
        temp[0] = temp[1]%1000000007;
        temp[1] = sum;
    }

}
